package com.bt.lms.ui.page.teaching.supervise;

import com.bt.lms.ui.action.teaching.supervise.PageTeachingSuperviseLookCourseResourceBtnAction;
import com.bt.lms.ui.vo.DetailStuInfo;
import com.bt.lms.ui.page.teaching.supervise.action.RealTimeClassBtn;
import com.bt.lms.ui.page.teaching.supervise.action.TeachingCheckBtn;
import com.bt.lms.ui.page.teaching.supervise.action.GradeBtn;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import java.util.ArrayList;
import java.util.List;

/**
 * 教学监管 点击教学监管  查看学员界面
 */
public class LookStu extends VBox {

    /**
     * 查看学员界面长
     */
    private double preWidth = 1280;
    /**
     * 查看学员界面高
     */
    private double preHeight = 800;

    /**
     *列名默认长度
     */
    private double columnPreWidth = 100;

    public LookStu(){

        this.setPrefSize(preWidth,preHeight);
        this.setPadding(new Insets(5));
        this.setSpacing(20);

        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //按钮横向盒子
        HBox buttonHBox = new HBox();
        initButtonHBox(buttonHBox);
        //详细来源盒子
        HBox detailHBox = new HBox();
        initDetailHBox(detailHBox);
        //班级详情盒子
        HBox classDetailHBox = new HBox();
        initClassDetailHBox(classDetailHBox);
        //搜索区域盒子
        HBox searchHBox = new HBox();
        initSearchHBox(searchHBox);
        //表格盒子
        VBox tableVBox = new VBox();
        initTableVBox(tableVBox);
        //页码横向盒子
        HBox pageNumHBox = new HBox();
        initPageNumHBox(pageNumHBox);



        ObservableList<Node> children = this.getChildren();
        children.addAll(topHBox,buttonHBox,detailHBox,classDetailHBox,searchHBox,tableVBox,pageNumHBox);


    }

    /**
     * 页码横向盒子
     * @param pageNumHBox
     */
    private void initPageNumHBox(HBox pageNumHBox) {
        pageNumHBox.setSpacing(20);
        pageNumHBox.setPadding(new Insets(10));
        pageNumHBox.setAlignment(Pos.CENTER_RIGHT);
        //首页标签
        Label homeLab = new Label("<<首页");
        homeLab.setTextFill(Color.rgb(108,221,83));
        homeLab.setFont(new Font(20));
        //上一页标签
        Label previousPageLab = new Label("<<上一页");
        previousPageLab.setTextFill(Color.rgb(108,221,83));
        previousPageLab.setFont(new Font(20));
        //第一页按钮
        Button onePageBtn = new Button("1");
        onePageBtn.setPrefWidth(27);
        onePageBtn.setPrefHeight(30);
        //第二页按钮
        Button twoPageBtn = new Button("2");
        twoPageBtn.setPrefWidth(27);
        twoPageBtn.setPrefHeight(30);
        //第三页按钮
        Button threePageBtn = new Button("3");
        threePageBtn.setPrefWidth(27);
        threePageBtn.setPrefHeight(30);
        //第四页按钮
        Button fourPageBtn = new Button("4");
        fourPageBtn.setPrefWidth(27);
        fourPageBtn.setPrefHeight(30);
        //下一页标签
        Label nextPageLab = new Label("下一页>>");
        nextPageLab.setFont(new Font(20));
        nextPageLab.setTextFill(Color.rgb(108,221,83));
        //尾页标签
        Label endPageLab = new Label("尾页>>");
        endPageLab.setFont(new Font(20));
        endPageLab.setTextFill(Color.rgb(108,221,83));
        //总记录数条
        Label totalPageLab = new Label("总页数100条");
        totalPageLab.setFont(new Font(20));
        totalPageLab.setTextFill(Color.rgb(255,65,55));
        //条数文本框
        TextField countTF = new TextField();
        countTF.setPrefWidth(100);
        // /10标签
        Label tenLab = new Label("/10");
        tenLab.setFont(new Font(20));
        //GO按钮
        Button goBtn = new Button("GO");
        ObservableList<Node> children = pageNumHBox.getChildren();
        children.addAll(homeLab,previousPageLab,onePageBtn,twoPageBtn,threePageBtn,fourPageBtn,nextPageLab,endPageLab,totalPageLab,countTF,tenLab,goBtn);
    }

    /**
     * 表格盒子
     * @param tableVBox
     */
    private void initTableVBox(VBox tableVBox) {

        //表格
        TableView tableView = new TableView<>();

        TableColumn serialNumColumn = new TableColumn<>("序号");
        serialNumColumn.setPrefWidth(columnPreWidth);
        TableColumn stuNumColumn = new TableColumn<>("学员编号");
        stuNumColumn.setPrefWidth(columnPreWidth);
        TableColumn nameColumn = new TableColumn<>("姓名");
        nameColumn.setPrefWidth(columnPreWidth);
        TableColumn genderColumn = new TableColumn<>("性别");
        genderColumn.setPrefWidth(columnPreWidth);
        TableColumn enpColumn = new TableColumn<>("招生计划");
        enpColumn.setPrefWidth(columnPreWidth);
        TableColumn gradeColumn = new TableColumn<>("班级");
        gradeColumn.setPrefWidth(columnPreWidth);
        TableColumn specialtyColumn = new TableColumn<>("专业");
        specialtyColumn.setPrefWidth(columnPreWidth);
        TableColumn phoneNumColumn = new TableColumn<>("手机号码");
        phoneNumColumn.setPrefWidth(columnPreWidth+columnPreWidth);
        TableColumn accountColumn = new TableColumn<>("账号");
        accountColumn.setPrefWidth(columnPreWidth+columnPreWidth);


        //模拟表中数据
        DetailStuInfo detailStuInfo1 = new DetailStuInfo("1","456123","张三","男","招生计划A","班级A","专业A","13113245432","zs@qq.com");
        DetailStuInfo detailStuInfo2 = new DetailStuInfo("2","455463","小明","男","招生计划B","班级B","专业B","13113245432","xm@qq.com");
        DetailStuInfo detailStuInfo3 = new DetailStuInfo("3","45654","李四","女","招生计划A","班级A","专业A","13113245432","ls@qq.com");
        //数据集合
        List<DetailStuInfo>detailStuInfoList = new ArrayList<>();
        detailStuInfoList.add(detailStuInfo1);
        detailStuInfoList.add(detailStuInfo2);
        detailStuInfoList.add(detailStuInfo3);
        //将数据集合转换成Javafx组件集合
        ObservableList<DetailStuInfo>detailStuInfos = FXCollections.observableArrayList(detailStuInfoList);
        tableView.setItems(detailStuInfos);
        //映射到表中
        serialNumColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("serialNum"));
        stuNumColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("stuNum"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("name"));
        genderColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("gender"));
        enpColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("enp"));
        gradeColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("grade"));
        specialtyColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("specialty"));
        phoneNumColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("phoneNum"));
        accountColumn.setCellValueFactory(new PropertyValueFactory<DetailStuInfo,String>("account"));


        //所有的列放到表格里
        tableView.getColumns().addAll(serialNumColumn,stuNumColumn,nameColumn,genderColumn,enpColumn,gradeColumn,specialtyColumn,phoneNumColumn,accountColumn);



        tableVBox.getChildren().add(tableView);


    }

    /**
     * 搜索区域盒子
     * @param searchHBox
     */
    private void initSearchHBox(HBox searchHBox) {

        searchHBox.setPadding(new Insets(5));
        searchHBox.setSpacing(20);
        //学员编号标签
        Label stuNumLab = new Label("学员编号");
        //学员编号文本框
        TextField stuNumTF = new TextField();
        //姓名标签
        Label nameLab = new Label("姓名");
        //姓名文本框
        TextField nameTF = new TextField();
        //账号标签
        Label accountLab = new Label("帐号");
        //账号文本框
        TextField accountTF = new TextField();
        //导出按钮
        Button exportBtn = new Button("导出");
        ObservableList<Node> children = searchHBox.getChildren();
        children.addAll(stuNumLab,stuNumTF,nameLab,nameTF,accountLab,accountTF,exportBtn);
    }

    /**
     * 班级详情盒子
     * @param classDetailHBox
     */
    private void initClassDetailHBox(HBox classDetailHBox) {

        classDetailHBox.setPadding(new Insets(5));
        classDetailHBox.setSpacing(20);
        //招生计划A班标签
        Label applyALab = new Label("招生计划：A班(15/30)");
        //招生计划B班标签
        Label applyBLab = new Label("招生计划:B班(11/45)");
        classDetailHBox.getChildren().addAll(applyALab,applyBLab);
    }

    /**
     * 详细来源盒子
     * @param detailHBox
     */
    private void initDetailHBox(HBox detailHBox) {

        detailHBox.setPadding(new Insets(5));
        //标签
        Label detailLab = new Label("共计：100人,详细来源如下:");
        detailHBox.getChildren().add(detailLab);
    }

    /**
     * 按钮横向盒子
     * @param buttonHBox
     */
    private void initButtonHBox(HBox buttonHBox) {

        buttonHBox.setSpacing(20);
        buttonHBox.setPadding(new Insets(5));
        //查看学员按钮
        Button lookStuBtn = new Button("查看学员");
        //查看课程资源按钮
        Button lookCourseResourceBtn = new Button("查看课程资源");
        ObservableList<Node> children = buttonHBox.getChildren();
        children.addAll(lookStuBtn,lookCourseResourceBtn);
        //查看课程资源按钮事件
        PageTeachingSuperviseLookCourseResourceBtnAction pageTeachingSuperviseLookCourseResourceBtnAction = new PageTeachingSuperviseLookCourseResourceBtnAction();
        lookCourseResourceBtn.setOnAction(pageTeachingSuperviseLookCourseResourceBtnAction);

        //教师值机按钮
        Button teachingCheckBtn = new Button("教师值机管理");
        ObservableList<Node> teachingCheckBtnChildren = buttonHBox.getChildren();
        teachingCheckBtnChildren.add(teachingCheckBtn);
        //事件
        TeachingCheckBtn teachingCheckBtnAction = new TeachingCheckBtn();
        teachingCheckBtn.setOnAction(teachingCheckBtnAction);

        //实时课堂按钮
        Button realTimeClassBtn = new Button("实时课堂管理");
        ObservableList<Node> realTimeClassBtnChildren = buttonHBox.getChildren();
        realTimeClassBtnChildren.add(realTimeClassBtn);
        RealTimeClassBtn realTimeClassBtnAction = new RealTimeClassBtn();
        realTimeClassBtn.setOnAction(realTimeClassBtnAction);

        //成绩及结业按钮
        Button gradeBtn = new Button("成绩及结业管理");
        ObservableList<Node> gradeBtnChildren = buttonHBox.getChildren();
        gradeBtnChildren.add(gradeBtn);
        GradeBtn gradeBtnBtnAction = new GradeBtn();
        gradeBtn.setOnAction(gradeBtnBtnAction);

    }

    /**
     * 顶部横向盒子
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {
        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(5));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>教学管理>教学监督>已完成的教学安排>查看教学监管历史数据");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }
}
